package com.yootk.servlet;

import com.yootk.common.util.factory.ServiceFactory;
import com.yootk.service.IMessageService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/message.action")
public class MessageServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取要操作的业务接口对象实例，此时返回的是代理设计的实例
        IMessageService messageService = ServiceFactory.getServiceInstance("message.service", IMessageService.class);
        try {
            req.setAttribute("messageList", messageService.list());
        } catch (Exception e) {
            e.printStackTrace();
        }
        req.getRequestDispatcher("/message.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
